'use strict';

module.exports = function countSameElements(collection) {
    let arr = [] ;
    let obj = {} ;
    for(let item of collection){
        if(item.length != 1){
            if(!obj[item[0]]){
                obj[item[0]] = {} ;
                obj[item[0]].name = item[0] ;
                obj[item[0]].summary = parseInt(item.replace(/[^0-9]/ig,''));
            }else{
                obj[item[0]].summary +=  parseInt(item.replace(/[^0-9]/ig,''));
            }
        }else{
            if(!obj[item]){
                obj[item] = {} ;
                obj[item].name = item ;
                obj[item].summary = 1;
            }else{
                obj[item].summary ++ ;
            }
        }
    }
    for(let value in obj){
        arr.push(obj[value]) ;
    }
    return arr ;
}
// let a = "a:81"
// console.log(a.replace(/[^0-9]/ig,"")) ;
//^反义字符，replace替换函数,将所有不是数字的用空代替
//i 忽略大小写，g全局匹配
